package com.lxl.bt.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;

import com.google.gson.JsonObject;
import com.lxl.bt.Constant;
import com.lxl.bt.R;
import com.lxl.bt.net.NetApi;
import com.lxl.bt.net.Result;
import com.lxl.bt.retorfit.NetCallback;
import com.lxl.bt.retorfit.RetrofitUtil;
import com.lxl.bt.util.ACache;
import com.lxl.bt.util.Prefs;
import com.lxl.bt.util.ToastUtil;
import com.yanzhenjie.sofia.Sofia;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Create by lvxinlong
 * on 设置
 * on  2021年3月5日22:21:43
 **/
public class SettingActivity extends BaseActivity {


    @BindView(R.id.ivBack)
    ImageView ivBack;
    @BindView(R.id.rlBack)
    RelativeLayout rlBack;
    @BindView(R.id.txt_toolbar_title)
    TextView txtToolbarTitle;
    @BindView(R.id.ivRight)
    ImageView ivRight;
    @BindView(R.id.tvRight)
    TextView tvRight;
    @BindView(R.id.rlRight)
    RelativeLayout rlRight;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.etName)
    EditText etName;
    @BindView(R.id.etPhone)
    EditText etPhone;
    @BindView(R.id.tvWx)
    TextView tvWx;
    @BindView(R.id.tvPassword)
    TextView tvPassword;
    @BindView(R.id.tvMoneySetting)
    TextView tvMoneySetting;
    @BindView(R.id.tvShiMin)
    TextView tvShiMin;
    @BindView(R.id.tvCommit)
    TextView tvCommit;
    private Context context;
    ACache aCache;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        //状态栏全透明全屏显示页面，布局能够延伸到状态栏和导航栏下方
        Sofia.with(this)
                .invasionStatusBar()
                .statusBarLightFont()
//                .statusBarDarkFont()
                .statusBarBackgroundAlpha(0)
                .invasionNavigationBar()
                .navigationBarBackgroundAlpha(0);

        context = this;
        rlBack.setVisibility(View.VISIBLE);
        txtToolbarTitle.setText("设置");
        aCache = ACache.get(this);
    }

    private void commit() {
        aCache.remove(Constant.LOGIN);
        Prefs.savePre(Constant.JSESSIONID,"");
        finish();
//        JsonObject jsonObject = new JsonObject();
//        RetrofitUtil.getInstance().create(NetApi.class, 0)
//                .logout(jsonObject).enqueue(new NetCallback<Result<String>>() {
//            @Override
//            public void onSuccess(Result<String> result) {
//                Log.w("lxl", ">>>>" + result.isSuccess());
//                if (result.isSuccess()) {
//                    aCache.remove(Constant.LOGIN);
//                    finish();
//                } else {
//                    ToastUtil.showToast(SettingActivity.this, result.getMsg());
//                }
//
//            }
//
//            @Override
//            public void netLogin() {
//
//            }
//
//            @Override
//            public void onError(String errorStr) {
//                super.onError(errorStr);
//                Log.w("lxl", ">>>>" + errorStr);
//                ToastUtil.showToast(SettingActivity.this, errorStr);
//            }
//
//        });
    }

    @OnClick({R.id.rlBack, R.id.tvWx, R.id.tvPassword, R.id.tvMoneySetting, R.id.tvShiMin, R.id.tvCommit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rlBack:
                finish();
                break;
            case R.id.tvWx:
                startActivity(new Intent(this,WxBindActivity.class));
                break;
            case R.id.tvPassword:
                startActivity(new Intent(this,ForgetPasswordActivity.class));
                break;
            case R.id.tvMoneySetting:
                break;
            case R.id.tvShiMin:
                startActivity(new Intent(this,ShiMinRenZhenActivity.class));
                break;
            case R.id.tvCommit:
                commit();
                break;
        }
    }
}
